#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct ListNode {
    int val;
    struct ListNode* next;
    ListNode(int x) : val(x), next(nullptr) {}
    
};
ListNode* mergeKLists(vector<ListNode*>& lists) {
    // write code here

    vector<int> tmp;
    for (auto it : lists)
    {
        ListNode* head = it;
        while (head)
        {
            tmp.push_back(head->val);
            head = head->next;
        }
    }
    sort(tmp.begin(), tmp.end());
    ListNode* newHead = nullptr;
    if (!tmp.empty())
        newHead = new ListNode(tmp[0]);
    ListNode* tail = newHead;

    int num = tmp.size();
    for (int i = 1; i < num; i++)
    {
        ListNode* cur = new ListNode(tmp[i]);
        if (tail)
            tail->next = cur;
        tail = cur;
    }
    return newHead;

}
int main()
{
	return 0;
}
